package com.loong.controller;

import com.loong.dto.ClazzDTO;
import com.loong.entity.Clazz;
import com.loong.result.PageBean;
import com.loong.result.Result;
import com.loong.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result<PageBean> list(ClazzDTO clazzDTO) {
        return Result.success(clazzService.list(clazzDTO));
    }

    @GetMapping("/list")
    public Result<List<Clazz>> list() {
        return Result.success(clazzService.listAll());
    }

    @GetMapping("/{id}")
    public Result<Clazz> get(@PathVariable Integer id) {
        return Result.success(clazzService.get(id));
    }

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable Integer id) {
        clazzService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result<?> insert(@RequestBody Clazz clazz) {
        clazzService.insert(clazz);
        return Result.success();
    }

    @PutMapping
    public Result<?> update(@RequestBody Clazz clazz) {
        clazzService.update(clazz);
        return Result.success();
    }
}
